package com.houkunlin.configuration;

import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.WebBindingInitializer;

/**
 * 普通请求字符串参数去除首尾空格
 *
 * @author HouKunLin
 */
@Configuration
@ControllerAdvice
public class StringTrimWebBindingInitializer implements WebBindingInitializer {
    @InitBinder
    @Override
    public void initBinder(final WebDataBinder binder) {
        final StringTrimmerEditor editor = new StringTrimmerEditor(false);
        binder.registerCustomEditor(String.class, editor);
    }
}
